﻿/* Write a program that extracts from a given text all palindromes, e.g. "ABBA", "lamal", "exe". */
using System;
using System.Text.RegularExpressions;

namespace _20.Palindromes
{
    class Palindromes
    {
        static void Main()
        {
            string str = "my abba is very lamal exe today and I am very tired of this shit because it is 22:02 and I write this homework all day and I am very very tired now.";
            Regex r = new Regex(@"\w+");
            foreach (Match m in r.Matches(str))
            {
                Console.WriteLine("{0} is a palindrome? {1}", m.Groups[0].Value, CheckIfPalindrome(m.Groups[0].Value));
            }
        }

        private static object CheckIfPalindrome(string palindromecandidate)
        {
            for (int i = 0; i < palindromecandidate.Length / 2; i++)
                if (palindromecandidate[i] == palindromecandidate[palindromecandidate.Length-i-1]) return true;
            return false;
        }
    }
}
